|
|
|
|
|
|
|
she is continuously redirected back to the login page. If this were a real application, you might want to have a counter that alerts an administrator after a certain number of failed attempts. |
|
|
|
|
CAUTION
|
|
|
|
|
The type of security described here can be thought of as application-level security. It does not provide network-level security. For example, someone could use specialized hardware to listen to the network transmissions to and from the Web servermuch like tapping a telephone lineto determine your password. To prevent this kind of spying, you need to investigate a secure connection using the https protocol. |
|
|
|
|
|
|
|
|
|
|
Because a browser operates on a request-and-response basis, the user does not really establish a continuous connection with the Web server. Therefore, the server has no real way of knowing when the connection is broken, so a session will timeout after a certain number of minutes. You control this with the TimeOut property of the Session object: |
|
|
|
|
|
|
|
|
Executing the previous statement causes the timeout to be set to 60 minutes. After 60 minutes of inactivity, the server ends the user's session, destroying any session variables. You can also purposely end a session with the Abandon method, as in the following line of code: |
|
|
|
|
|
|
|
|
Controlling Output with the Response Object |
|
|
|
|
|
|
|
|
Another useful object in Active Server Pages is the Response object. You have already been introduced to Response.Write, which is used to send HTML or other text back to the browser. |
|
|
|
|
|
|
|
|
The Response.Write Statement |
|
|
|
|
|
|
|
|
You can build a string in the Response.Write statement by using the string concatenation operator (&), as in the following example: |
|
|
|
|
|
|
|
|
<%
Response.Write ("Hello, " & Session("USERID") & "<BR>")
%> |
|
|
|
|
|
|
|
|
|
You can also use the short script tags and the equals sign (=) to send the contents of a variable back to the browser, as in the following example: |
|
|
|
|
|
|
|
|
Hello, <% =Session("USERID") %><BR> |
|
|
|
|
|
|
|
|
I prefer using the Response.Write method, but this short form is good when you need to embed a simple value in your HTML.  |
|
|
|
|
|
|
|
|
|
|
In addition to standard HTML, you can use Response.Write to generate client-side script from the server. For example, consider the following segment of ASP code: |
|
|
|
|
|
|
|
|
<%
sString = "This is an ASP variable"
Response.Write (vbCrLf & "<SCRIPT LANGUAGE=VBScript>" & vbCrLf) |
|
|
|
|
|